package com.isunland.managesystem.ui;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.NavUtils;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;
import android.widget.TextView;
import android.widget.Toast;
import butterknife.BindView;
import butterknife.ButterKnife;
import com.android.volley.VolleyError;
import com.google.gson.Gson;
import com.google.gson.JsonSyntaxException;
import com.isunland.managesystem.R;
import com.isunland.managesystem.base.BaseConfirmDialogFragment;
import com.isunland.managesystem.base.BaseFragment;
import com.isunland.managesystem.base.BaseNetworkDialogFragment;
import com.isunland.managesystem.base.BaseTimeDialogFragment;
import com.isunland.managesystem.base.BaseVolleyActivity;
import com.isunland.managesystem.base.BaseYMDTimeDialogFragment;
import com.isunland.managesystem.common.ApiConst;
import com.isunland.managesystem.common.VolleyResponse;
import com.isunland.managesystem.entity.CurrentUser;
import com.isunland.managesystem.entity.CustomerDialog;
import com.isunland.managesystem.entity.ProcessContent;
import com.isunland.managesystem.entity.SuccessMessage;
import com.isunland.managesystem.utils.DateUtil;
import com.isunland.managesystem.utils.LogUtil;
import com.isunland.managesystem.utils.MessageUtil;
import com.isunland.managesystem.utils.MyUtils;
import com.isunland.managesystem.utils.ToastUtil;
import com.isunland.managesystem.widget.CheckLineView;
import java.util.Date;
import java.util.HashMap;
import org.json.JSONException;

public class WorkProcessEditFragment extends BaseFragment implements OnClickListener {
  public static final String EXTRA_PROCESS_CONTENT =
      "com.isunland.managesystem.ui.extra_process_content";
  protected static final String TAG = WorkProcessEditFragment.class.getSimpleName();
  /**
   * 本阶段完成时间
   */
  private static final int REQUEST_CHOOSE_TIME = 0;
  private static final int REQUEST_DELETE_TEMPPLAN = 1;
  /**
   * 要求完成时间
   */
  private static final int REQUEST_ACQUIRE_FINISHTIME = 2;
  /**
   * 委派人
   */
  private static final int REQUEST_CHOOSE_APOINTER = 3;
  /**
   * 计划类别
   */
  private static final int REQUEST_PLAN_KIND = 4;
  HashMap<String, String> mProcessEdit;
  private BaseVolleyActivity mActivity;
  private TextView mTvProgressFinishTime;// 完成时间
  private EditText mEtProgressDegree;// 完成度
  private EditText mEtProgressWorkTime;// 所用工时
  private EditText mEtProgressContent;// 完成情况
  private TextView mTvPlanAppointer;// 委派人
  private TextView mTvPlanTime;// 要求完成时间
  private TextView mTvPlanKind;// 计划类别
  private ProcessContent mProcessContent;
  // WorkProcess.ProcessContent processContent;
  private String mIfEnd = "F";

  private Callbacks mCallbacks;
  private String mApointer;
  private String mId;
  private CurrentUser mUser;
  @BindView(R.id.clv_report) CheckLineView clvReport;

  // int item
  public static WorkProcessEditFragment newInstance(ProcessContent item) {
    Bundle bundle = new Bundle();
    bundle.putSerializable(EXTRA_PROCESS_CONTENT, item);

    WorkProcessEditFragment editFragment = new WorkProcessEditFragment();
    editFragment.setArguments(bundle);
    return editFragment;
  }

  @SuppressWarnings("deprecation") @Override public void onAttach(Activity activity) {
    super.onAttach(activity);
    mCallbacks = (Callbacks) activity;
  }

  @Override public void onDetach() {
    super.onDetach();
    mCallbacks = null;
  }

  @Override
  // 返回按钮
  public void onCreate(Bundle savedInstanceState) {
    setHasOptionsMenu(true);
    mActivity = (BaseVolleyActivity) getActivity();
    if (NavUtils.getParentActivityName(getActivity()) != null) {
      if (mActivity.getSupportActionBar() != null) {

        mActivity.getSupportActionBar().setDisplayHomeAsUpEnabled(true);
      }
    }

    mUser = CurrentUser.newInstance(getActivity());
    mProcessContent = (ProcessContent) getArguments().getSerializable(EXTRA_PROCESS_CONTENT);
    if (mProcessContent != null) {
      mApointer = mProcessContent.getTaskManName();
    }
    //		// 判断是添加还是修改.
    //		if (mProcessContent == null) {
    //			isEdit = false;
    //		} else {
    //			isEdit = true;
    //		}

    super.onCreate(savedInstanceState);
  }

  @Override public View onCreateView(LayoutInflater inflater, ViewGroup container,
      Bundle savedInstanceState) {
    // ( (BaseVolleyActivity) getActivity()).getSupportActionBar().setTitle(R.string.latestConditionRegedit);
    View view = inflater.inflate(R.layout.fragment_workprocess_edit, container, false);
    ButterKnife.bind(this, view);
    initView(view);

    return view;
  }

  private void initView(View view) {
    mEtProgressContent = (EditText) view.findViewById(R.id.et_putFinishCondition_workProcess);
    mTvProgressFinishTime = (TextView) view.findViewById(R.id.et_putFinishTime_workProcess);
    mEtProgressDegree = (EditText) view.findViewById(R.id.et_putFinishPercent_workProcess);
    mEtProgressWorkTime = (EditText) view.findViewById(R.id.et_putUseTime_workProcess);
    mEtProgressContent = (EditText) view.findViewById(R.id.et_putFinishCondition_workProcess);
    EditText mEtPlanContent = (EditText) view.findViewById(R.id.tv_planContent_workProcess);
    mTvPlanAppointer = (TextView) view.findViewById(R.id.tv_appointer_workProcess);
    mTvPlanTime = (TextView) view.findViewById(R.id.tv_requestFinishTime_workProcess);
    mTvPlanKind = (TextView) view.findViewById(R.id.tv_planClass_workProcess);
    Button mBtnDelete = (Button) view.findViewById(R.id.bt_deleteTempPlan_workProcess);
    TextView mtvExecutorAddWorkProcess =
        (TextView) view.findViewById(R.id.tv_executor_WorkProcessEdit);
        /*
      是否完成
     */
    RadioGroup mRgIsFinish = (RadioGroup) view.findViewById(R.id.rg_isFinish_workProcess);
    RadioButton mRbFalse = (RadioButton) view.findViewById(R.id.rb_false_workProcess);
    mRbFalse.setChecked(true);
    mRgIsFinish.setOnCheckedChangeListener(new OnCheckedChangeListener() {

      @Override public void onCheckedChanged(RadioGroup group, int checkedId) {
        switch (checkedId) {
          case R.id.rb_true_workProcess:
            mIfEnd = "T";
            mEtProgressDegree.setText(String.valueOf(100));
            mEtProgressDegree.setEnabled(false);

            break;
          case R.id.rb_false_workProcess:
            mIfEnd = "F";
            mEtProgressDegree.setText("0");
            mEtProgressDegree.setEnabled(true);
            break;

          default:
            break;
        }
      }
    });
    mTvProgressFinishTime.setOnClickListener(this);
    mTvPlanTime.setOnClickListener(this);
    //		if (isEdit) {
    // 编辑状态下是传过来的id
    mId = mProcessContent.getId();
    // 修改时禁用计划编辑文本框
    mEtPlanContent.setEnabled(false);
    // 修改时禁用要求完成时间.
    mTvPlanTime.setEnabled(false);
    // 修改时初始化数据.
    mEtPlanContent.setText(mProcessContent.getPlanContentDesc());
    mTvPlanAppointer.setText(mProcessContent.getTaskManName());
    mTvPlanTime.setText(mProcessContent.getPlanEsteTime());
    mTvPlanKind.setText(mProcessContent.getPlanKindName());
    if (!TextUtils.isEmpty(mProcessContent.getExcManName())) {
      mtvExecutorAddWorkProcess.setText(mProcessContent.getExcManName());
    }
    // 如果是编辑状态并且是临时计划,添加删除按钮.
    //String tempPlan = getString(R.string.plan_temp);
    setDeleteButtonStatus(mProcessContent, mBtnDelete);

    mEtProgressDegree.setHint(R.string.finishPercentComplete);
    mTvProgressFinishTime.setHint(R.string.chooseTimeComplete);
    mEtProgressWorkTime.setHint(R.string.useCompleteTime);
    mEtProgressWorkTime.setText("0.0");
    mEtProgressContent.setHint(R.string.finishConditionComplete);
    //		} else {
    //			// 添加是自动生成id
    //			mId = UUID.randomUUID().toString();
    //			// 添加时设置监听器.
    //			mTvPlanAppointer.setOnClickListener(this);
    //			mTvPlanTime.setOnClickListener(this);
    //			mTvPlanKind.setOnClickListener(this);
    //			mEtProgressDegree.setHint(R.string.finishCompletePercent);
    //			mTvProgressFinishTime.setHint(R.string.chooseCompleteTime);
    //			mEtProgressWorkTime.setHint(R.string.useCompleteTime);
    //			mEtProgressContent.setHint(R.string.finishCompleteCondition);
    //		}
    //		// 无论是添加还是修改,生成id后将id存放在sp中,用于登记成功后刷新进度列表界面.
    //		SharedPreferencesUtil.setString(getActivity(), SharedPreferencesUtil.MAIN_ID, mId);
  }

  private void setDeleteButtonStatus(ProcessContent content, Button mBtnDelete) {
    try {
      if (!"Temp".equalsIgnoreCase(content.getPlanKindTypeCode())) {
        //只能删除临时任务
        return;
      }

      if ("archive".equalsIgnoreCase(content.getEvaStatus()) || "eval".equalsIgnoreCase(
          content.getEvaStatus())) {
        //已评价或归档内容不允许删除
        return;
      }

      if (!content.getRegStaffId().equalsIgnoreCase(mUser.getJobNumber())) {
        //只能删除自己登记的任务
        return;
      }

      mBtnDelete.setVisibility(View.VISIBLE);
      mBtnDelete.setOnClickListener(this);
    } catch (Exception e) {
      LogUtil.e("delete button error", e);
    }
  }

  // 判断要填写的是否填写完整及对于书写的验证
  private void saveWorkProcessEdit() {
    boolean isEmpty = MyUtils.isEmptyText(mTvProgressFinishTime)
        || MyUtils.isEmptyText(mEtProgressDegree)
        || MyUtils.isEmptyText(mEtProgressContent);
    if (isEmpty) {
      Toast.makeText(getActivity(), R.string.completeWriteWrokProgress, Toast.LENGTH_SHORT).show();
      return;
    }

    // 对输入完成度进行校验
    String completePercent = mEtProgressDegree.getText().toString();
    int percent = Integer.parseInt(completePercent);
    if (percent < 0 || percent > 100) {
      Toast.makeText(getActivity(), R.string.finishPercentError, Toast.LENGTH_SHORT).show();
      return;
    }

    //如果未完成，完成度不能填写100
    String finishDegree = mEtProgressDegree.getText().toString().trim();
    int degree = Integer.parseInt(finishDegree);
    if ("F".equalsIgnoreCase(mIfEnd) && degree == 100) {
      ToastUtil.show(R.string.chooseBrforeHandr);
      return;
    }

    // 提交提示对话框
    AlertDialog.Builder dialog = new AlertDialog.Builder(mActivity);
    dialog.setTitle(R.string.restart_title);
    dialog.setMessage(R.string.cannotEditWorkProgress);

    dialog.setPositiveButton(R.string.confirm, new DialogInterface.OnClickListener() {

      @Override public void onClick(DialogInterface dialog, int which) {
        volleyPostSaveProgress();
      }
    });

    dialog.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {

      @Override public void onClick(DialogInterface dialog, int which) {
        dialog.dismiss();
      }
    });
    dialog.create().show();
  }

  private void volleyPostSaveProgress() {
    String url = ApiConst.getAbsoluteUrl(ApiConst.URL_PROGRESS);

    String completeTime = mTvProgressFinishTime.getText().toString();
    String completePercent;

    try {
      int percent = Integer.parseInt(mEtProgressDegree.getText().toString().trim());
      completePercent = percent + "";
    } catch (Exception e) {
      e.printStackTrace();
      completePercent = "0";
    }
    String completeUseTime = mEtProgressWorkTime.getText().toString();
    final String completeCondition = mEtProgressContent.getText().toString();

    mProcessEdit = new HashMap<>();
    mProcessEdit.put("mainid", mId);
    mProcessEdit.put("ifEnd", mIfEnd);

    mProcessEdit.put("completeDate", completeTime);
    mProcessEdit.put("excDesc", completeCondition);
    mProcessEdit.put("rateCurrent", completePercent);
    if (TextUtils.isEmpty(completeUseTime)) {
      mProcessEdit.put("workTimeNum", "0");
    } else {
      mProcessEdit.put("workTimeNum", completeUseTime);
    }

    MyUtils.showDialogLoading(getActivity(), R.string.loadingSubmit);
    mActivity.volleyPost(url, mProcessEdit, new VolleyResponse() {

      @Override public void onVolleyResponse(String arg0) throws JSONException {
        SuccessMessage workProcess;
        try {
          MyUtils.dismissDialog();
          workProcess = new Gson().fromJson(arg0, SuccessMessage.class);
          if (null == workProcess || null == workProcess.getResult()) {
            Toast.makeText(getActivity(), R.string.failure_operation, Toast.LENGTH_SHORT).show();
            return;
          }
          String successType = workProcess.getResult();
          if (successType.equals(SuccessMessage.FAILURE)) {
            Toast.makeText(getActivity(), R.string.failure_operation, Toast.LENGTH_SHORT).show();
            return;
          }
          if (successType.equals(SuccessMessage.SUCCESS)) {
            //进展填报成功后如果勾选了汇报发站内信
            if (clvReport.getCbCheck().isChecked() && (mProcessContent != null)) {
              MessageUtil.sendReport(mActivity, mProcessContent.getTaskManId(),
                  mProcessContent.getTaskManName(), completeCondition);
            }
            Toast.makeText(getActivity(), R.string.success_operation, Toast.LENGTH_SHORT).show();
            mEtProgressDegree.setText("");
            mEtProgressWorkTime.setText("0.0");
            mEtProgressContent.setText("");
            mTvProgressFinishTime.setText("");
            // 如果工作计划已完成，就刷新工作计划列表。
            if (mIfEnd.equals("T")) {
              getActivity().setResult(Activity.RESULT_OK);
            }
            mCallbacks.onRefresh();
          }
        } catch (JsonSyntaxException e) {
          e.printStackTrace();
        }
      }

      @Override public void onVolleyError(VolleyError arg0) {
        // Auto-generated method stub

      }
    });
  }

  //private boolean isEditProgress() {
  //    boolean isNotEdit = MyUtils.isEmptyText(mTvProgressFinishTime) && MyUtils.isEmptyText(mEtProgressDegree)
  //            && MyUtils.isEmptyText(mEtProgressWorkTime) && MyUtils.isEmptyText(mEtProgressContent);
  //    return !isNotEdit;
  //}

  @Override public void onClick(View arg0) {
    switch (arg0.getId()) {
      case R.id.et_putFinishTime_workProcess:
        showDialog(REQUEST_CHOOSE_TIME, new Date());
        break;
      case R.id.bt_deleteTempPlan_workProcess:
        showDialog(REQUEST_DELETE_TEMPPLAN, null);

        break;

      case R.id.tv_appointer_workProcess:

        showDialog(REQUEST_CHOOSE_APOINTER, null);

        break;
      case R.id.tv_planClass_workProcess:

        showDialog(REQUEST_PLAN_KIND, null);

        break;
      case R.id.tv_requestFinishTime_workProcess:

        showDialog(REQUEST_ACQUIRE_FINISHTIME, new Date());

        break;
      default:
        break;
    }
  }

  /**
   * 显示时间对话框
   *
   * @param requestCode 请求码
   * @param date 对话框初始显示时间
   */
  public void showDialog(int requestCode, Date date) {

    DialogFragment dialog;
    FragmentManager fm = getActivity().getSupportFragmentManager();
    switch (requestCode) {
      case REQUEST_CHOOSE_TIME:// 本阶段完成时间.
        dialog = WorkProgressTimeDialogFragment.newInstance(date, R.string.chooseThisStageTime);
        break;

      case REQUEST_DELETE_TEMPPLAN:
        dialog = BaseConfirmDialogFragment.newInstance(R.string.deleteConfirm);
        break;
      case REQUEST_ACQUIRE_FINISHTIME:
        dialog = new BaseYMDTimeDialogFragment();
        break;

      case REQUEST_CHOOSE_APOINTER:
        // dialog = new AppointerDialogFragment();
        // break;
        Intent i = new Intent(getActivity(), AppointerListActivity.class);
        // i.putExtra(AppointerListFragment.EXTRA_FROM,
        // AppointerListFragment.VALUE_TO_DO);
        startActivityForResult(i, requestCode);
        return;

      case REQUEST_PLAN_KIND:
        Intent intent = new Intent(getActivity(), PlanKindListActivity.class);
        startActivityForResult(intent, requestCode);
        return;

      default:
        return;
    }
    dialog.setTargetFragment(WorkProcessEditFragment.this, requestCode);
    dialog.show(fm, "");
  }

  // 响应返回按钮
  @Override public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
      case android.R.id.home:
        if (NavUtils.getParentActivityName(getActivity()) != null) {
          NavUtils.navigateUpFromSameTask(getActivity());
        }
        return true;
      // 保存进展
      case R.id.menu_item_confirm:
        saveWorkProcessEdit();
        return true;
      // 工作转办
      case R.id.menu_item_convert:
        WorkConvert();
        return true;
      // 任务分配
      case R.id.menu_item_distribute:
        Intent intent = new Intent(getActivity(), WorkDistributeListActivity.class);
        intent.putExtra(WorkDistributeListFragment.EXTRA_CONTENT, mProcessContent);
        startActivity(intent);
        return true;

      default:
        return super.onOptionsItemSelected(item);
    }
  }

  //private boolean isEditProgress() {
  //    boolean isNotEdit = MyUtils.isEmptyText(mTvProgressFinishTime) && MyUtils.isEmptyText(mEtProgressDegree)
  //            && MyUtils.isEmptyText(mEtProgressWorkTime) && MyUtils.isEmptyText(mEtProgressContent);
  //    return !isNotEdit;
  //}

  // 确认按钮
  @Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    //MenuInflater menuInflater = new MenuInflater(getActivity());
    inflater.inflate(R.menu.menu_workprocess, menu);
    //		if (isEdit) {
    //
    //			menuInflater.inflate(R.menu.menu_workprocess, menu);
    //		} else {
    //			menuInflater.inflate(R.menu.menu_confirm, menu);
    //
    //		}
    super.onCreateOptionsMenu(menu, inflater);
  }

  //	// 判断要填写的是否填写完整及对于书写的验证
  //	private void addTempPlan() {
  //		if (TextUtils.isEmpty(mTvPlanAppointer.getText().toString())) {
  //			ToastUtil.show(R.string.chooseAppointer);
  //			return;
  //		}
  //
  //		boolean isEmpty = MyUtils.isEmptyText(mTvPlanTime) || MyUtils.isEmptyText(mTvPlanKind)
  //				|| MyUtils.isEmptyText(mEtPlanContent);
  //
  //		if (isEmpty) {
  //			Toast.makeText(getActivity(), R.string.complete, Toast.LENGTH_SHORT).show();
  //			return;
  //		}
  //		volleyPostAddPlan();
  //	}
  //
  //	private void volleyPostAddPlan() {
  //		String url = ApiConst.getAbsoluteUrl(ApiConst.URL_TEMPORARY_PLAN);
  //
  //		String planContent = mEtPlanContent.getText().toString();
  //
  //		// 无代表清空委派人
  //
  //		if (null == mApointerJobNo || mApointerJobNo.equals("clear")) {
  //			mApointerJobNo = "";
  //			mApointer = "";
  //		}
  //
  //		HashMap<String, String> params = new HashMap<String, String>();
  //		params.put("id", mId);
  //		params.put("taskManName", mApointer);
  //		params.put("taskManId", mApointerJobNo);
  //		params.put("planEsteTime", mAcquireTime);
  //		params.put("planKindName", mPlanKindName);
  //		params.put("planKindCode", mPlanKindCode);
  //		params.put("planContentDesc", planContent);
  //		MyUtils.showDialogLoading(mActivity);
  //		mActivity.volleyPost(url, params, new VolleyResponse() {
  //
  //			@Override
  //			public void onVolleyResponse(String arg0) throws JSONException {
  //
  //				try {
  //					MyUtils.dismissDialog();
  //
  //					SuccessMessage workProcess = new Gson().fromJson(arg0, SuccessMessage.class);
  //					if (null == workProcess || null == workProcess.getResult()) {
  //						Toast.makeText(getActivity(), R.string.failure_operation, Toast.LENGTH_SHORT).show();
  //						return;
  //
  //					}
  //					String successType = workProcess.getResult();
  //					if (successType.equals(SuccessMessage.FAILURE)) {
  //						Toast.makeText(getActivity(), R.string.failure_operation, Toast.LENGTH_SHORT).show();
  //						return;
  //					}
  //					if (successType.equals(SuccessMessage.SUCCESS)) {
  //						Toast.makeText(getActivity(), R.string.addTempPlan, Toast.LENGTH_SHORT).show();
  //						// 添加临时计划成功,刷新列表
  //						getActivity().setResult(Activity.RESULT_OK);
  //						// 同时判断是否需要进展情况登记.
  //						if (isEditProgress()) {
  //
  //							saveWorkProcessEdit();
  //						} else {
  //							// 不需要进展登记,直接返回列表页面
  //							getActivity().finish();
  //						}
  //
  //					}
  //				} catch (JsonSyntaxException e) {
  //					e.printStackTrace();
  //				}
  //
  //			}
  //
  //			@Override
  //			public void onVolleyError(VolleyError arg0) {
  //
  //			}
  //		});
  //	}

  private void WorkConvert() {
    Intent intent = new Intent(getActivity(), WorkprocessConvertActicity.class);
    intent.putExtra(WorkprocessConvertFragment.EXTRA_VALUE, mProcessContent);
    startActivity(intent);
  }

  @Override public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode != Activity.RESULT_OK) return;
    if (requestCode == REQUEST_CHOOSE_TIME && data != null) {
      Date chooseDate = (Date) data.getSerializableExtra(BaseTimeDialogFragment.EXTRA_DATE);
      String chooseDateString = DateUtil.dateToString(chooseDate);
      mTvProgressFinishTime.setText(chooseDateString);

      return;
    }

    if (requestCode == REQUEST_DELETE_TEMPPLAN) {
      volleyPostDelete();

      return;
    }
    if (requestCode == REQUEST_ACQUIRE_FINISHTIME && data != null) {
      Date acquireDate = (Date) data.getSerializableExtra(BaseYMDTimeDialogFragment.EXTRA_DATE);

      String mAcquireTime = DateUtil.dateToString(acquireDate, DateUtil.TYPE_DATE);
      mTvPlanTime.setText(mAcquireTime);

      return;
    }

    if (requestCode == REQUEST_CHOOSE_APOINTER && data != null) {
      CustomerDialog customer =
          (CustomerDialog) data.getSerializableExtra(BaseNetworkDialogFragment.EXTRA_VALUE);
      mApointer = customer.getName();
      String mApointerJobNo = customer.getId();
      // clear代表清空所选 委派人.
      if (mApointerJobNo != null && !mApointerJobNo.equalsIgnoreCase("clear")) {
        mTvPlanAppointer.setText(mApointer);
      } else {
        mTvPlanAppointer.setText("");
      }

      return;
    }

    if (requestCode == REQUEST_PLAN_KIND && data != null) {
      CustomerDialog planKind =
          (CustomerDialog) data.getSerializableExtra(BaseNetworkDialogFragment.EXTRA_VALUE);
      String mPlanKindName = planKind.getName();
      //String mPlanKindCode = planKind.getId();
      mTvPlanKind.setText(mPlanKindName);
    }
    super.onActivityResult(requestCode, resultCode, data);
  }

  /**
   * 删除临时计划
   */
  private void volleyPostDelete() {
    MyUtils.showDialogLoading(getActivity());
    String url = ApiConst.getAbsoluteUrl(ApiConst.URL_TEMPLAN_DELETE);
    HashMap<String, String> params = new HashMap<>();
    params.put("id", mId);
    mActivity.volleyPost(url, params, new VolleyResponse() {

      @Override public void onVolleyResponse(String arg0) throws JSONException {
        SuccessMessage workProcess;
        try {
          MyUtils.dismissDialog();
          workProcess = new Gson().fromJson(arg0, SuccessMessage.class);
          if (null == workProcess || null == workProcess.getResult()) {
            Toast.makeText(getActivity(), R.string.failure_operation, Toast.LENGTH_SHORT).show();
            return;
          }
          String successType = workProcess.getResult();
          if (successType.equals(SuccessMessage.FAILURE)) {
            Toast.makeText(getActivity(), R.string.failure_operation, Toast.LENGTH_SHORT).show();
            return;
          }
          if (successType.equals(SuccessMessage.SUCCESS)) {
            Toast.makeText(getActivity(), R.string.success_operation, Toast.LENGTH_SHORT).show();
            getActivity().setResult(Activity.RESULT_OK);
            getActivity().finish();
          }
        } catch (JsonSyntaxException e) {
          e.printStackTrace();
        }
      }

      @Override public void onVolleyError(VolleyError arg0) {
        Toast.makeText(getActivity(), R.string.deleteFail, Toast.LENGTH_SHORT).show();
      }
    });
  }

  @Override public void initMockData() {
    super.initMockData();
    mProcessContent = new ProcessContent();
    mProcessContent.setTaskManName("刘浩");
    mProcessContent.setTaskManId("112233");
    mProcessContent.setId("A5F50BBD6FBC4E8287B85A830913B6EE_40765");
    mProcessContent.setPlanContentDesc("(转办)测试已收到");
    mProcessContent.setPlanEsteTime("2017-06-22");
    mProcessContent.setPlanKindName("三维建模制作");
    mProcessContent.setExcManName("刘卫平");
    mApointer = mProcessContent.getTaskManName();
  }

  public interface Callbacks {
    void onRefresh();
  }
}
